//
//  NSDate+Additions.m
//  MyNotification
//
//  Created by zhyuan on 8/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NSDate+Additions.h"


@implementation NSDate(Additions)

// convert string to date by given format
+ (NSDate *)dateFromStringByFormat:(NSString *)string format:(NSString *)format
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format];
	[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
	NSDate *returnDate = [dateFormatter dateFromString:string];
	[dateFormatter release];
    return returnDate;    
}
// covert date to string by given format
+ (NSString *)dateToStringByFormat:(NSDate *)date format:(NSString *)format
{
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format];
	[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
	NSString *returnString = [dateFormatter stringFromDate:date];
	[dateFormatter release];
    return returnString;   
}

+ (NSString *)dateToStringByFormatWithSystemZone:(NSDate *)date format:(NSString *)format
{
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format];
	[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
	NSString *returnString = [dateFormatter stringFromDate:date];
	[dateFormatter release];
    return returnString;  
}
@end
